const Sequelize = require('sequelize');
const config = require('../../config');

const sequelize = new Sequelize({
    host: config.mysql.host,
    database: config.mysql.database,
    username: config.mysql.username,
    password: config.mysql.passport,
    port: config.mysql.port,
    dialect: 'mysql',
    pool: {
        max: 5,
        min: 0,
        idle: 10000
    },
    timezone: '+08:00'
});

//测试数据库链接
sequelize.authenticate().then(function() {
    console.log("数据库连接成功");
}).catch(function(err) {
    //数据库连接失败时打印输出
    console.error(err);
    throw err;
});

exports.sequelize = sequelize;